package emulator.hardware.io.porthistory;

import emulator.hardware.io.Via6522;
import emulator.history.BitStateHistory;
import emulator.util.events.EventAggregator;

public class PortStateHistory
{
	private int bufSize = 1000;
	
	private BitStateHistory [] portAin = new BitStateHistory [8];
	private BitStateHistory [] portAout = new BitStateHistory [8];
	private BitStateHistory [] portActrl = new BitStateHistory [2]; 
	
	private BitStateHistory [] portBin = new BitStateHistory [8];
	private BitStateHistory [] portBout = new BitStateHistory [8];
	private BitStateHistory [] portBctrl = new BitStateHistory [2]; 
	
	public PortStateHistory(Via6522 via, EventAggregator eventAggregator)
	{
		for (int i = 0; i < 8; i++)
		{
			portAin[i] = new BitStateHistory(bufSize);
			new PortStateCollector(eventAggregator, portAin[i], via, via.getPortA(), via.getPortA().getInPortBit(i));
			portAout[i] = new BitStateHistory(bufSize);
			new PortStateCollector(eventAggregator, portAout[i], via, via.getPortA(), via.getPortA().getOutPortBit(i));
			portBin[i] = new BitStateHistory(bufSize);
			new PortStateCollector(eventAggregator, portBin[i], via, via.getPortB(), via.getPortB().getInPortBit(i));
			portBout[i] = new BitStateHistory(bufSize);
			new PortStateCollector(eventAggregator, portBout[i], via, via.getPortB(), via.getPortB().getOutPortBit(i));
		}
		for (int i = 0; i < 2; i++)
		{
			portActrl[i] = new BitStateHistory(bufSize);
			new PortStateCollector(eventAggregator, portActrl[i], via, via.getPortA(), via.getPortA().getControlBit(i));
			portBctrl[i] = new BitStateHistory(bufSize);
			new PortStateCollector(eventAggregator, portBctrl[i], via, via.getPortB(), via.getPortB().getControlBit(i));
		}
	}

	public BitStateHistory getPortAin(int index)
	{
		return portAin[index];
	}

	public BitStateHistory getPortAout(int index) 
	{
		return portAout[index];
	}

	public BitStateHistory getPortActrl(int index)
	{
		return portActrl[index];
	}

	public BitStateHistory getPortBin(int index)
	{
		return portBin[index];
	}

	public BitStateHistory getPortBout(int index) 
	{
		return portBout[index];
	}

	public BitStateHistory getPortBctrl(int index)
	{
		return portBctrl[index];
	}
}
